package cn.kgc.tangcco.pojo;

import cn.hutool.core.util.IdcardUtil;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;

/**
 * @author 李昊哲
 * @Description
 * @create 2020/10/20 上午10:17
 */
@Getter
@Setter
@NoArgsConstructor
public class Person {
    /**
     * 数据库主键
     */
    private Integer id;
    /**
     * 手机号
     */
    private String mobile;
    /**
     * 姓名
     */
    private String nickname;
    /**
     * 密码
     */
    private String authString;
    /**
     * 身份证号
     */
    private String idCard;
    /**
     * 性别 1代表男性 2代表女
     */
    private Integer gender;
    /**
     * 年龄
     */
    private Integer age;
    /**
     * 出生日期
     */
    @JSONField(format = "yyyy-MM-dd")
    private Date birthday;

    public void setIdCard(String idCard) {
        this.idCard = idCard;
        this.gender = IdcardUtil.getGenderByIdCard(idCard);
        this.age = IdcardUtil.getAgeByIdCard(idCard);
        this.birthday = IdcardUtil.getBirthDate(idCard);
    }

    public Person(Integer id, String mobile, String nickname, String authString, String idCard) {
        this.id = id;
        this.mobile = mobile;
        this.nickname = nickname;
        this.authString = authString;
        this.idCard = idCard;
        this.gender = IdcardUtil.getGenderByIdCard(idCard);
        this.age = IdcardUtil.getAgeByIdCard(idCard);
        this.birthday = IdcardUtil.getBirthDate(idCard);
    }
}
